package net.zjitc.controller;

import net.zjitc.domain.Category;
import net.zjitc.domain.CategorySecond;
import net.zjitc.service.Impl.ServiceImpl;
import net.zjitc.service.Service;
import org.apache.commons.beanutils.BeanUtils;
import utils.dispacher.URLMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.InvocationTargetException;
import java.sql.SQLException;
import java.util.List;

/**
 * Created by Administrator on 2017/11/22.
 */
public class Product {
    Service service=new ServiceImpl();
    //显示列表
    @URLMapping(url = "/AdminCategorySecondFindAll")
    public String findAll(HttpServletRequest request, HttpServletResponse response)
    {
        List<CategorySecond> allCategory = service.findAllCategorySecond();
        request.setAttribute("list",allCategory);
        return "/admin/categorysecond/list.jsp";
    }
    @URLMapping(url = "/AdminCategorySecondAddUI")
    public String addUI(HttpServletRequest request, HttpServletResponse response)
    {
        List<Category> clist=service.findAllCategory();
        request.setAttribute("clist",clist);
        return "/admin/categorysecond/add.jsp";
    }
    @URLMapping(url = "/AdminCategorySecondAdd")
    public String add(HttpServletRequest request, HttpServletResponse response) throws InvocationTargetException, IllegalAccessException {
        Category category=new Category();
        CategorySecond categorySecond=new CategorySecond();
        BeanUtils.populate(category,request.getParameterMap());
        BeanUtils.populate(categorySecond,request.getParameterMap());
        categorySecond.setCategory(category);
        int num=service.addCategorySecond(categorySecond);

        String url=request.getContextPath()+"/AdminCategorySecondFindAll";
        return "Redirect:"+url;
    }
    @URLMapping(url = "/AdminCategorySecondEditUI")
    public String editUI (HttpServletRequest request, HttpServletResponse response) throws InvocationTargetException, IllegalAccessException, SQLException {
        String csid=request.getParameter("csid");
        CategorySecond categorySecond=service.findCategorySecondId(csid);
        request.setAttribute("cs",categorySecond);
        List<Category> list=service.findAllCategory();
        request.setAttribute("list",list);
        String url=request.getContextPath()+"/AdminCategorySecondFindAll";
        return "Redirect:"+url;
    }
    @URLMapping(url = "/AdminCategorySecondEdit")
    public String edit(HttpServletRequest request, HttpServletResponse response)
    {
        String url=request.getContextPath()+"/AdminCategorySecondFindAll";
        return "Redirect:"+url;
    }
    @URLMapping(url = "/AdminCategorySecondDelete")
    public String delete(HttpServletRequest request, HttpServletResponse response)
    {
        String url=request.getContextPath()+"/AdminCategorySecondFindAll";
        return "Redirect:"+url;
    }
}
